package com.zz.spring6.xmltx.service;

import com.zz.spring6.xmltx.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

//@Transactional(isolation = Isolation.DEFAULT//使用数据库默认的隔离级别
// @Transactional(isolation= IsolatiOn.READ UNCOMMITTED)读未提交
// @Transactional(isolation= Isolation.READ_COMMITTED)//读已提交
// @Transactional(isolation = IsolatiOn.REPEATABLE_READ)//可重复读
// @Transactional(isolation= Isolation.SERIALIZABLE)//串行化


@Service
public class BookServiceImpl implements BookService {


    @Autowired
    private BookDao bookDao;


    @Override
    public void buyBook(Integer boosId, Integer userId) {

        Integer price =bookDao.getBookPriceByBookId(boosId);

        bookDao.updateStock(boosId);

        bookDao.updateUserBalance(userId,price);

    }
}
